<template>
  <!-- 头部搜索部分 -->
  <div class="g-layout-header-userHandl">
    <!-- 左头像 -->
    <div class="headLeft">
      <div class="headLeft-box">
        <img
          id="headLeftImg"
          src="@/assets/logo.png"
          alt=""
        />
      </div>
    </div>
    <!-- 中间搜索 -->
    <div class="searchTitle">
      <van-search
        class="searchInp"
        shape="round"
        placeholder="请输入搜索关键词"
        @focus="handleSearch"
      />
    </div>
    <!-- 右边邮件 -->
    <div
      class="headRight"
      @click="setTheme"
    >
      <img
        id="headRightImg"
        src="@/assets/icon-img/youjian.png"
        alt=""
      />
    </div>
  </div>
</template>

<script>
import { computed } from 'vue'
import { useRouter } from 'vue-router'
import { useStore } from 'vuex'
export default {
  props: {
    // 搜索关键字
    keyword: {
      type: String
    }
  },
  setup() {
    // 搜索的方法
    const router = useRouter()
    const store = useStore()
    const handleSearch = () => {
      router.push('/search')
    }
    const themeName = computed(() => store.state.theme.themeName)
    const setTheme = () => {
      store.dispatch('theme/SET', themeName.value === 'light' ? 'dark' : 'light')
    }
    return {
      handleSearch,
      setTheme
    }
  }
}
</script>

<style lang="scss" scoped>
// 头部搜索
.g-layout-header-userHandl {
  display: flex;
  justify-content: center;
  align-items: center;
  // 左边头像icon
  .headLeft {
    flex: 1;
    .headLeft-box {
      border-radius: 100%;
      width: 35px;
      height: 35px;
      margin-left: 10px;
      overflow: hidden;
      #headLeftImg {
        width: 100%;
      }
    }
  }
  // 中间搜索
  .searchTitle {
    flex: 7;
  }
  .headRight {
    flex: 1;
    // icon邮件
    #headRightImg {
      width: 25px;
    }
  }
}
</style>
